<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class CheckoutUserInfoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if (Auth::check()) {
            return [
                'country'=>'required',
                'state'=>'required',
                'city'=>'required',
                'pincode'=>'required|min:6',
                'fullname'=>'required'
            ];
        } else {
            return [
            'name'=>'required',
            'username'=>'required',
            'password'=>'required|confirmed'
        ];
        }
    }

    public function messages()
    {
        return [
         'name.required'=>'名称不能为空',
         'username.required'=>'用户名不能为空',
         'password.required'=>'密码不能为空',
         'password.confirmed'=>'两次密码不一致',
         'city.required'=>'城市不能为空',
         'state.required'=>'省不能为空',
         'country.required'=>'国家必选',
         'pincode.required'=>'邮政编码不能为空',
         'pincode.min'=>'邮政编码格式不正确',
         'fullname.required'=>'详细地址不能为空',
        ];
    }
}
